package com.lieve.bpm.command.editor;

/**
 * @author sunyoboy
 * 2021/6/4
 */
public class EditorCommand implements Command {

    private Content content;

    public EditorCommand(Content content) {
        this.content = content;
    }

    @Override
    public void didIt() {
        printContent();
        content.setMessage(content.getMessage() + getAppendMessage());
        content.setVersion(content.getVersion() + 1);
        printContent();
    }

    public void printContent() {
        System.out.println(content.getVersion() + " : " + content.getMessage());
    }

    @Override
    public void undo() {
        int indexOfAppendMessage = content.getMessage().lastIndexOf(getAppendMessage());
        content.setMessage(content.getMessage().substring(0, indexOfAppendMessage));
        content.setVersion(content.getVersion() - 1);
        printContent();
    }

    public String getAppendMessage() {
        return "doIt();";
    }
}
